<template>
	<page  ref='page'>
		<!-- 商品列表 wwl -->
		<view class="page">
			<view class="list" v-if="list && list.length  > 0">
				<view class="row" v-for="(row,index) in list" :key='index' >
					<image :src="row.cover" mode="scaleToFill" class="left" @click="onDetail(2,row.id)"></image>
					<view class="right" @click="onDetail(2,row.id)">
						<view class="top">
							<view class="top_name">
								{{row.name}}
							</view>
							<!-- 
							<view class="top_btn2" @click="onDetail(3,row.id)">
								编辑
							</view> -->
						</view>
						
						<view class="center">
							当前状态：{{row.s_status == 1 ? '上架' : '下架' }}
						</view>
						<view class="center">
							浏览量：{{row.pageviews}}
						</view>
						<view class="top_btn">
							交易地址：{{row.address}}
						</view>
					</view>
					<view :class="row.s_status == 1 ? 'xiajia2' : 'xiajia'" class="zuobianju" @click="getsxJia(row,1)">
						{{row.s_status == 1 ? '下架' : '上架' }}
					</view>
					<view class="zuobianju xiajia2" v-if="row.status == 1" @click="getsxJia(row,2)">
						删除
					</view>
					<view :class="row.status == 1 ? 'xiajia2' : 'xiajia'" class="zuobianju" v-if="row.status != 1">
						{{row.status == 1 ? '审核通过' : row.status == 2 ? '驳回' : '审核中' }}
					</view>
				</view>
			</view>
			<empty v-else />
			<view class="bottom_box">
				<view class="btn" :class="theme" @click="onDetail(1,null)">
					新增商品
				</view>
			</view>
		</view>
	</page>
</template>

<script>
	import {
		getmyGoods,getsxJia
	} from "../static/api.js"
	import { mapState,mapMutations,mapGetters } from 'vuex'
	export default {
		data() {
			return {
				type: null,
				page: 1,
				total: 0,
				size: 10,
				loading: false,
				list: []
			}
		},
		methods: {
			onDetail(status, id) {
				uni.navigateTo({
					url: `/pagesGoods/goods/details?status=${status}&id=${id}&type=${this.type}`
				})
			},
			//获取默认列表
			async getList() {
				if (this.page == 1) uni.showLoading()
				this.loading = true
				try {
					var res = await getmyGoods({
						laiyuan: 1,
						page: this.page,
						limit: this.size
					})
					this.list = this.page == 1 ? res.list : [...this.list, ...res.list]
					if (this.page == 1) uni.hideLoading()
					this.loading = false
				} catch {
					uni.hideLoading()
					this.loading = false
				}
			},
			//切换上架下架
			async getsxJia(row,type) {
				uni.showLoading()
				
				var res = await getsxJia({
						id: row.id,
						type: type,
						s_status: row.s_status
				})
				uni.hideLoading()
				if(res.code == 200){
					// this.$global.$editUploadBack(1,'shopList')
					uni.showToast({title:res.msg,duration: 2000})
					this.total = 0
					this.page = 1
					this.getList()
				}else{
					uni.showToast({title:res.msg,duration: 2000,icon:'none'})
				}
				
				
			}
		},
		computed: {
			...mapGetters('theme', ['theme']),
			...mapState(['theme']),
			
		},
		onLoad(params) {
			this.type = params.type
			// this.getList()
		},
		onReachBottom(x) {
			if (this.page * this.size >= this.total || this.loading) return
			this.page++
			this.getList()
		},
		onShow() {
			this.total = 0
			this.page = 1
			this.getList()
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		padding-bottom: 200rpx;
	}

	.list {
		width: 100%;
		padding: 0 36rpx;
		box-sizing: border-box;
		margin-top: 20rpx;

		.row {
			width: 100%;
			margin-bottom: 10rpx;
			min-height: 228rpx;
			background: #ffffff;
			border-radius: 20rpx;
			box-shadow: 0px 6rpx 30rpx 0px rgba(0, 0, 0, 0.08);
			display: flex;
			justify-content: space-between;
			padding: 20rpx 20rpx;
			box-sizing: border-box;
			
			.xiajia{
				width: 38px;
				box-sizing: border-box;
				    background: #ff9b03;
				    border-radius: 10px;
				    color: #fff;
				    font-size: 16px;
				    display: flex;
				    justify-content: center;
				    flex-direction: row;
				    align-items: center;
				    text-align: center;
			}
			.xiajia2{
				width: 38px;
				box-sizing: border-box;
				    background: #999;
				    border-radius: 10px;
				    color: #fff;
				    font-size: 16px;
				    display: flex;
				    justify-content: center;
				    flex-direction: row;
				    align-items: center;
				    text-align: center;
			}
			.left {
				width: 160rpx;
				height: auto;
				margin-right: 20rpx;
				// border-radius: 50%;
			}

			.right {
				width: calc(100% - 120rpx);

				.top {
					display: flex;
					flex-wrap: wrap;
				}

				.top_name {
					color: #26252A;
					font-size: 28rpx;
					line-height: 40rpx;
					max-width: calc(100% - 200rpx);
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					margin-right: 20rpx;
				}

				.top_btn {
					margin-right: 10px;
					margin-top: 8px;
					min-width: 80rpx;
					padding: 0 16rpx;
					// height: 40rpx;
					line-height: 40rpx;
					box-sizing: border-box;
					// text-align: center;
					line-height: 40rpx;
					background: $theme;
					border-radius: 20rpx;
					color: #fff;
					font-size: 24rpx;
				}

				.top_btn2 {
					margin-left: 20rpx;
					width: 80rpx;
					height: 36rpx;
					text-align: center;
					line-height: 36rpx;
					border: 2rpx solid $theme;
					border-radius: 20rpx;
					color: $theme;
					font-size: 24rpx;
				}

				.center {
					margin-top: 16rpx;
					font-size: 20rpx;
					line-height: 28rpx;
					color: #999999;
				}

				.bottom {
					width: 100%;

					.bottom_left {
						margin-top: 16rpx;
						display: inline-block;
						width: calc(100% - 128rpx);
						padding-right: 20rpx;
						box-sizing: border-box;
						font-size: 20rpx;
						line-height: 28rpx;
						color: #999999;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}

					.bottom_right {
						vertical-align: top;
						display: inline-block;
						width: 128rpx;
						height: 50rpx;
						line-height: 50rpx;
						text-align: center;
						background: $theme;
						border-radius: 26rpx;
						font-size: 24rpx;
						color: #fff;
					}
				}
			}
		}
	}

	.bottom_box {
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 9;
		background-color: #fff;
		padding: 30rpx 36rpx 40rpx;

		.btn {
			width: 678rpx;
			height: 88rpx;
			line-height: 88rpx;
			text-align: center;
			// background: linear-gradient(270deg, #ff7a1f, #ff9760);
			border-radius: 200rpx;
			font-size: 28rpx;
			color: #fff;
		}
	}
	
	.zuobianju{
		margin-left: 5px;
	}
</style>
